﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PMSA.Framework.Log;

public partial class Admin_Uc_News_NewsManager : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CreateDDLGroupNews();
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        News obj = new News();
        string title = txtTitle.Text;
        string description = txtDescription.Text;
        string content = txtContent.Text;
        
        int createdUserId = 1;
        int groupNewsId = int.Parse(ddlGroupNews.SelectedValue);
        int status = int.Parse(txtStatus.Text);
        int isactive = cbxIsActive.Checked ? 1 : 0;

        string _photoNull = "../Img/layout/sample_large.jpg";
        string _photoLink = "../Admin/Upload/Image/News/";
        string _photo1 = _photoNull;
        if (!String.IsNullOrEmpty(photos1.Value))
        {
            _photo1 = _photoLink + photos1.Value;
        }
        obj.Insert(title, _photo1, content, description, createdUserId, groupNewsId, status, isactive);
    }
    private void CreateDDLGroupNews()
    {
        try
        {
            GroupNews obj = new GroupNews();
            IList<GroupNews> list = obj.List();
            ddlGroupNews.DataValueField = "Id";
            ddlGroupNews.DataTextField = "Name";
            ddlGroupNews.DataSource = list;
            ddlGroupNews.DataBind();
        }
        catch (Exception ex)
        {
            CLogManager.Write("News.Add.CreateDDLGroupNews", ex.ToString(), "ERR");
        }
    }
}